home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / HENSA / MATHS / PLPLOT / PLPLOT.ZIP / sys / amiga / old / plwindow.c < prev   
Encoding:
C/C++ Source or Header  |  1993-03-16  |  4.0 KB  |  159 lines

  1. /* $Id: plwindow.c,v 1.1 1993/03/15 21:30:59 mjl Exp $
  2.    $Log: plwindow.c,v $
  3.  * Revision 1.1  1993/03/15  21:30:59  mjl
  4.  * Files shuffled around in the Amiga driver reorganization.
  5.  *
  6.  * Revision 1.2  1992/10/12  17:11:29  mjl
  7.  * Amiga-specific mods, including ANSI-fication.
  8.  *
  9.  * Revision 1.1  1992/05/20  21:35:30  furnish
  10.  * Initial checkin of the whole PLPLOT project.
  11.  *
  12. */
  13.  
  14. #include "plplot.h"
  15. #include <stdio.h>
  16. #include <math.h>
  17. #include "plamiga.h"
  18.  
  19. extern struct PLPrefs PLCurPrefs;
  20.  
  21. PLINT MaxColors;
  22.  
  23. extern PLFLT InitWSize, InitHSize;
  24.  
  25. struct Screen *PLScreen;    /* For Custom Screen */
  26. struct Window *PLWindow;
  27. struct RastPort *PLSRPort;    /* Screen rastport */
  28. struct RastPort *PLWRPort;    /* Window rastport */
  29. struct ViewPort *PLVPort;
  30. struct ColorMap *PLCMap;
  31. static struct TmpRas PLTmpRas;
  32. static PLANEPTR PLTmpPlane;
  33.  
  34. struct NewWindow NewWindow =
  35. {
  36.     0, 0,
  37.     0, 0,
  38.     0, 1,
  39.     0,
  40.     0,
  41.     NULL,
  42.     NULL,
  43.     NULL,
  44.     NULL,            /* Screen pointer */
  45.     NULL,
  46.     205, 120, 1000, 1000,
  47.     WBENCHSCREEN
  48. };
  49.  
  50. void 
  51. OpenPLWind(void)
  52. {
  53.     short i;
  54.  
  55.     if (PLCurPrefs.WinType & PLCUST) {
  56.     struct NewScreen NewScreen =
  57.     {
  58.         0, 0, 0, 0, 1,
  59.         0, 1,
  60.         HIRES,        /* default viewmode */
  61.         CUSTOMSCREEN,
  62.         NULL,
  63.         "Plplot Screen",
  64.         NULL,
  65.         NULL
  66.     };
  67.  
  68.     NewScreen.Height = GfxBase->NormalDisplayRows;
  69.     NewScreen.Width = GfxBase->NormalDisplayColumns;
  70.  
  71.     if (PLCurPrefs.ScrType & PLLACE) {
  72.         NewScreen.ViewModes |= INTERLACE;
  73.         NewScreen.Height *= 2;
  74.     }
  75.     if (!(PLCurPrefs.ScrType & PLHIRES)) {
  76.         NewScreen.ViewModes &= ~HIRES;
  77.         NewScreen.Width /= 2;
  78.     }
  79.  
  80.     NewScreen.Depth = PLCurPrefs.Depth;
  81.     NewWindow.Type = CUSTOMSCREEN;
  82.     if ((PLScreen = OpenScreen(&NewScreen)) == NULL) {
  83.         fprintf(stderr, "Not enough memory for custom screen.\n");
  84.         CloseLibs();
  85.         pl_exit();
  86.     }
  87.     for (i = 0, MaxColors = 1; i < PLCurPrefs.Depth; i++)
  88.         MaxColors *= 2;
  89.     PLVPort = &(PLScreen->ViewPort);
  90.     LoadRGB4(PLVPort, &(PLCurPrefs.Color[0]), MaxColors);
  91.     NewWindow.Screen = PLScreen;
  92.     if (PLCurPrefs.CWidth == 0 || PLCurPrefs.CHeight == 0) {
  93.         NewWindow.Width = PLScreen->Width;
  94.         NewWindow.Height = PLScreen->Height - PLScreen->BarHeight - 1;
  95.         NewWindow.LeftEdge = 0;
  96.         NewWindow.TopEdge = PLScreen->BarHeight + 1;
  97.         PLCurPrefs.CXPos = NewWindow.Width;
  98.         PLCurPrefs.CYPos = NewWindow.Height;
  99.         PLCurPrefs.CWidth = NewWindow.Width;
  100.         PLCurPrefs.CHeight = NewWindow.Height;
  101.     }
  102.     else {
  103.         NewWindow.LeftEdge = PLCurPrefs.CXPos;
  104.         NewWindow.TopEdge = PLCurPrefs.CYPos;
  105.         NewWindow.Width = PLCurPrefs.CWidth;
  106.         NewWindow.Height = PLCurPrefs.CHeight;
  107.     }
  108.     }
  109.     else {
  110.     MaxColors = 4;
  111.     NewWindow.LeftEdge = PLCurPrefs.WXPos;
  112.     NewWindow.TopEdge = PLCurPrefs.WYPos;
  113.     NewWindow.Width = PLCurPrefs.WWidth;
  114.     NewWindow.Height = PLCurPrefs.WHeight;
  115.     NewWindow.Type = WBENCHSCREEN;
  116.     }
  117.  
  118.     NewWindow.IDCMPFlags = NEWSIZE | MENUPICK | CLOSEWINDOW;
  119.     NewWindow.Flags = WINDOWDRAG | WINDOWDEPTH | WINDOWCLOSE | WINDOWSIZING |
  120.     SMART_REFRESH | ACTIVATE;
  121.     NewWindow.Title = "Plplot 4.0  Amiga window driver";
  122.  
  123.     if ((PLWindow = OpenWindow(&NewWindow)) == NULL) {
  124.     fprintf(stderr, "Error opening window.\n");
  125.     if (PLCurPrefs.WinType & PLCUST)
  126.         CloseScreen(PLScreen);
  127.     CloseLibs();
  128.     }
  129.  
  130.     if (!(PLCurPrefs.WinType & PLCUST))
  131.     PLScreen = PLWindow->WScreen;
  132.  
  133.     PLSRPort = &(PLScreen->RastPort);
  134.     PLWRPort = PLWindow->RPort;
  135.     PLVPort = &(PLScreen->ViewPort);
  136.     PLCMap = PLVPort->ColorMap;
  137.     PLTmpPlane = AllocRaster(PLScreen->Width, PLScreen->Height);
  138.     if (PLTmpPlane == NULL) {
  139.     CloseWindow(PLWindow);
  140.     if (PLCurPrefs.WinType & PLCUST)
  141.         CloseScreen(PLScreen);
  142.     fprintf(stderr, "Out of memory!");
  143.     }
  144.     InitTmpRas(&PLTmpRas, PLTmpPlane, RASSIZE(PLScreen->Width, PLScreen->Height));
  145.     PLWRPort->TmpRas = &PLTmpRas;
  146.  
  147.     MakePLMenu();
  148. }
  149.  
  150. void 
  151. ClosePLWind(void)
  152. {
  153.     FreeRaster(PLTmpPlane, PLScreen->Width, PLScreen->Height);
  154.     ClearMenuStrip(PLWindow);
  155.     CloseWindow(PLWindow);
  156.     if ((PLScreen->Flags & SCREENTYPE) == CUSTOMSCREEN)
  157.     CloseScreen(PLScreen);
  158. }
  159.